#include <iostream>

using std::cout;
using std::endl;

class Base
{
public:
    Base(long base = 0)
    : _base(base)
    {
        cout << "Base(long = 0)" << endl;
    }

    virtual 
    void print() const//虚函数
    {
        cout << "Base::print()" << endl;
        cout << "Base::_base = " << _base << endl;
    }

    ~Base()
    {
        cout << "~Base()" << endl;
    }
private:
    long _base;
};

class Derived
: public Base
{
public:
    Derived(long base = 0, long derived = 0)
    : Base(base)
    , _derived(derived)
    {
        cout << "Derived(long = 0, long  = 0)" << endl;
    }

    void print() const
    {
        cout << "Derived::print()" << endl;
        cout << "Derived::_derived = " << _derived << endl;
    }

    ~Derived()
    {
        cout << "~Derived()" << endl;
    }
private:
    long _derived;
};

void func(Base &ref)
{
    ref.print();//同一种指令
}

void test()
{
    cout << "sizeof(Base) = " << sizeof(Base) << endl;
    cout << "sizeof(Derived) = " << sizeof(Derived) << endl;

    cout << endl;
    Base base(10);//基类对象
    Derived derived(11, 22);//派生类对象

    cout << endl << endl;
    //Base &ref = base
    func(base);
    //Base &ref = derived
    func(derived);
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

